package cn.openbiotoken.impl;

import androidx.annotation.NonNull;

import java.util.HashMap;
import java.util.Map;

import cn.openbiotoken.BiometricsFeature;

public class BiometricsFeatureImpl<Feature> implements BiometricsFeature<Feature> {

    public BiometricsFeatureImpl() {
        super();
        extras = new HashMap<>();
    }

    @Override
    @NonNull
    public Feature getFeature() {
        return feature;
    }

    @Override
    public void setFeature(@NonNull final Feature feature) {
        this.feature = feature;
    }

    @Override
    public String getSupplier() {
        return supplier;
    }

    @Override
    public void setSupplier(@NonNull final String supplier) {
        this.supplier = supplier;
    }

    @Override
    public String getSubjectType() {
        return subjectType;
    }

    @Override
    public void setSubjectType(@NonNull final String subjectType) {
        this.subjectType = subjectType;
    }

    @Override
    public String getFeatureType() {
        return featureType;
    }

    @Override
    public void setFeatureType(@NonNull final String featureType) {
        this.featureType = featureType;
    }

    @Override
    public long getVersion() {
        return version;
    }

    @Override
    public void setVersion(final long version) {
        this.version = version;
    }

    @Override
    public void putExtra(@NonNull final String key, @NonNull final Float value) {
        extras.put(key, value);
    }

    @Override
    public void putExtra(@NonNull final String key, @NonNull final Long value) {
        extras.put(key, value);
    }

    @Override
    public float getFloatExtra(@NonNull final String key) {
        Object value = extras.get(key);
        if (null==value) {
            return 0.0F;
        } else if (value instanceof Number) {
            return ((Number)value).floatValue();
        } else {
            return 0.0F;
        }
    }

    @Override
    public long getLongExtra(@NonNull String key) {
        Object value = extras.get(key);
        if (null==value) {
            return 0L;
        } else if (value instanceof Number) {
            return ((Number)value).longValue();
        } else {
            return 0L;
        }
    }

    private Feature feature;

    private String supplier;

    private String subjectType;

    private String featureType;

    private long version;

    @NonNull
    private final Map<String, Object> extras;
}
